﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Jumpton.Persistent;
using Jumpton.Data;
using Jumpton.SFA.Server.Entity;

namespace Jumpton.SFA.Server.BusinessRule.CallRoute
{
    public class VisitSummaryManager
    {

        
        public bool UpdateRouteCustomers(decimal USER_ID, int ROUTE_FORCE, string CUSTOMERS, int ROUTENUMBER, String VISITDATE, Boolean ACTIVE)
        {
            return SqlData.ExecuteSP("[SP_SAVE_ROUTE_CUSTOMERS]", USER_ID, ROUTE_FORCE, CUSTOMERS, ROUTENUMBER, VISITDATE, ACTIVE) >= 0;
        }
    


        public bool Save(VISITS_SUMMARY summary)
        {
            if (summary != null)
            {
                //visits.LAST_UPDATE_TIME =decimal.Parse(BusinessLogic.GetDateTimeString(DateTime.Now));
                summary.Save();
                return true;
            }
            else
                return false;
        }

        public bool Update(VISITS_SUMMARY summary)
        {
            if (summary != null)
            {
                String sql = String.Format(@"UPDATE  VISITS_SUMMARY
                              SET 
                              [VISIT_ID] ='{1}'
                              ,[TASTE_PEOPLE_NO] = '{2}'
                              ,[BUY_NO] = '{3}'
                              ,[TASTE] = '{4}'
                              ,[TASTE_NOODLE_TYPE] = '{5}'
                              ,[TASTE_NOODLE_NO] = '{6}'
                              ,[GIFT_NAME] = '{7}'
                              ,[GIFT_NO] = '{8}'
                              ,[BAG_SALES_NO] ='{9}'
                              ,[CONTAINER_SALES_NO] = '{10}'
                               WHERE [ID] ='{0}'",summary.ID,summary.VISIT_ID,summary.TASTE_PEOPLE_NO,
                                               summary.BUY_NO,summary.TASTE,summary.TASTE_NOODLE_TYPE,
                                               summary.TASTE_NOODLE_NO,summary.GIFT_NAME,summary.GIFT_NO,
                                               summary.BAG_SALES_NO,summary.CONTAINER_SALES_NO );
                Jumpton.Data.SqlData.ExecuteSql(sql);
                return true;
            }
            else
                return false;
        }
        public VISITS_SUMMARY Load(String Id)
        {
            return (VISITS_SUMMARY)ObjectRow.Load(typeof(VISITS_SUMMARY), "this.ID='" + Id + "'");
        }

        public VISITS_SUMMARY GetVisitSummaryByVisitId(String VisitId)
        {
            return (VISITS_SUMMARY)ObjectRow.Load(typeof(VISITS_SUMMARY), "this.VISIT_ID='" + VisitId+"'");
        }

      
    }
}
